package View;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.ListModel;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controller.Sistema;
import Model.ServicioView;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GestionarServicios extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JComboBox<ServicioView> cmbSeleccionServicio;
	private JTextField txtPrecio;
	private JButton btnRefresh;
	private JList<ServicioView> lstServiciosPaquete;
	private JTextField txtUnidad;
	private JButton btnEliminarPaquete;
	private JButton btnCrearPaquete;
	private JButton btnGuardar;
	private JTextField txtDescuentoPaquete;
	private JLabel lblDescuentoPaquete;
	private JLabel lblUnidad;
	private JLabel lblPrecio;
	private JLabel lblSeleccionServicio;
	private ListModel<ServicioView> lstServiciosPaqueteModel;
	private ServicioView servicioSeleccionado;
	private ComboBoxModel<ServicioView> cmbSeleccionServicioModel;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				GestionarServicios inst = new GestionarServicios();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public GestionarServicios() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				cmbSeleccionServicioModel = new DefaultComboBoxModel<ServicioView>(Sistema.getInstancia().getServiciosDisponibles());
				cmbSeleccionServicio = new JComboBox<ServicioView>();
				getContentPane().add(cmbSeleccionServicio);
				cmbSeleccionServicio.setModel(cmbSeleccionServicioModel);
				cmbSeleccionServicio.setBounds(146, 12, 173, 23);
				cmbSeleccionServicio.addItemListener(new ItemListener(){
					public void itemStateChanged(ItemEvent arg0) {
						servicioSeleccionado = (ServicioView) cmbSeleccionServicio.getSelectedItem();
						if (cmbSeleccionServicio.getSelectedItem().getClass().getSimpleName().equals("Paquete")){
							lstServiciosPaqueteModel = new DefaultComboBoxModel<ServicioView>(servicioSeleccionado.getServicios());
							lstServiciosPaquete = new JList<ServicioView>();
							getContentPane().add(lstServiciosPaquete);
							lstServiciosPaquete.setModel(lstServiciosPaqueteModel);
							lstServiciosPaquete.setBounds(34, 94, 285, 49);
						}
						
					}
					
				});
			}
			{
				lblSeleccionServicio = new JLabel();
				getContentPane().add(lblSeleccionServicio);
				lblSeleccionServicio.setText("Servicio:");
				lblSeleccionServicio.setBounds(86, 15, 48, 16);
			}
			{
				lblPrecio = new JLabel();
				getContentPane().add(lblPrecio);
				lblPrecio.setText("Precio:");
				lblPrecio.setBounds(34, 62, 36, 16);
			}
			{
				txtPrecio = new JTextField();
				getContentPane().add(txtPrecio);
				txtPrecio.setBounds(82, 59, 64, 23);
			}
			{
				lblUnidad = new JLabel();
				getContentPane().add(lblUnidad);
				lblUnidad.setText("Unidad:");
				lblUnidad.setBounds(174, 62, 41, 16);
			}
			{
				txtUnidad = new JTextField();
				getContentPane().add(txtUnidad);
				txtUnidad.setBounds(227, 59, 92, 23);
			}
			{
				lblDescuentoPaquete = new JLabel();
				getContentPane().add(lblDescuentoPaquete);
				lblDescuentoPaquete.setText("Descuento:");
				lblDescuentoPaquete.setBounds(34, 175, 59, 16);
			}
			{
				txtDescuentoPaquete = new JTextField();
				getContentPane().add(txtDescuentoPaquete);
				txtDescuentoPaquete.setBounds(118, 172, 62, 23);
			}
			{
				btnGuardar = new JButton();
				getContentPane().add(btnGuardar);
				btnGuardar.setText("Guardar Cambios");
				btnGuardar.setBounds(12, 209, 106, 23);
			}
			{
				btnCrearPaquete = new JButton();
				getContentPane().add(btnCrearPaquete);
				btnCrearPaquete.setText("Crear Paquete");
				btnCrearPaquete.setBounds(153, 209, 88, 23);
				btnCrearPaquete.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e) {
						AltaPaquete app = new AltaPaquete();
						app.setLocationRelativeTo(null);
						app.setVisible(true);
					}
					
				});
			}
			{
				btnEliminarPaquete = new JButton();
				getContentPane().add(btnEliminarPaquete);
				btnEliminarPaquete.setText("Eliminar Paquete");
				btnEliminarPaquete.setBounds(252, 209, 103, 23);
			}
			{
				lstServiciosPaqueteModel = 
						new DefaultComboBoxModel<ServicioView>();
				lstServiciosPaquete = new JList<ServicioView>();
				getContentPane().add(lstServiciosPaquete);
				lstServiciosPaquete.setModel(lstServiciosPaqueteModel);
				lstServiciosPaquete.setBounds(34, 94, 285, 49);
			}
			{
				btnRefresh = new JButton();
				getContentPane().add(btnRefresh);
				btnRefresh.setText("Refresh");
				btnRefresh.setBounds(5, 12, 53, 23);
				btnRefresh.addActionListener(new ActionListener(){

					@Override
					public void actionPerformed(ActionEvent e) {
						cmbSeleccionServicioModel = new DefaultComboBoxModel<ServicioView>(Sistema.getInstancia().getServiciosDisponibles());
						cmbSeleccionServicio.setModel(cmbSeleccionServicioModel);						
					}
					
				});
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
